import pygame, random

def explosion(pos, spot_num = 30):
      for i in range(spot_num):
            flame_spot(pos)

class flame_spot(pygame.sprite.Sprite):

      def __init__(self, pos, x_speed = -1, y_speed = -1, size = -1, fade_speed = 5, range = 5):

            super(flame_spot, self).__init__(self.containers)

            if (size == -1):
                  self.size = random.randrange(1, 10)
            else:
                  self.size = size
            self.image = pygame.Surface((self.size, self.size))
            pygame.draw.ellipse(self.image, random.choice([(255, 244, 147),
                                                           (254, 228, 3), 
                                                           (167, 150, 1),
                                                           (251, 86, 15),
                                                           (253, 172, 138),
                                                           (255, 255, 255)]),
                                [0,0,self.size,self.size])
            self.image.set_colorkey((0,0,0), pygame.RLEACCEL)
            self.image.convert()
            self.rect = self.image.get_rect(center = pos)

            if (x_speed == -1 or y_speed == -1):
                  self.vx = random.randrange(-range, range)
                  self.vy = random.randrange(-range, range)
            else:
                  self.vx = x_speed
                  self.vy = y_speed

            self.trans = 255
            self.fade_speed = fade_speed

      def draw(self, screen):
            screen.blit(self.image, self.rect)

      def update(self):
            self.trans -= self.fade_speed
            if self.trans <= 0:
                  self.kill()
            self.image.set_alpha(self.trans)
            self.rect.move_ip(self.vx, self.vy)

      def destroy(self):
            pygame.sprite.Sprite.kill(self)
